package xiaohao.order.manager.impl;

import org.apache.commons.lang.StringUtils;

import com.taobao.api.domain.Trade;

import xiaohao.order.dao.TradeDao;
import xiaohao.order.domain.MemoDO;
import xiaohao.order.exception.TradeException;
import xiaohao.order.manager.TradeMemoManager;

public class DefaultTradeMemoManager implements TradeMemoManager {

	@Override
	public Trade buyerMemo(Trade trade, MemoDO memoDO, String sessionKey)
			throws TradeException {
		String buyerMemo = trade.getBuyerMemo();
		if (StringUtils.isEmpty(buyerMemo)) {
			return tradeDao.addMemo(trade.getTid(), memoDO, sessionKey);
		} else {
			return tradeDao.updateMemo(trade.getTid(), memoDO, sessionKey);
		}
	}

	private TradeDao tradeDao;

	public void setTradeDao(TradeDao tradeDao) {
		this.tradeDao = tradeDao;
	}
	
}
